package com.storm.service

import com.storm.feign.AuthFeign
import com.storm.util.log
import com.storm.model.JwtUser
import org.springframework.security.core.authority.SimpleGrantedAuthority
import org.springframework.security.core.userdetails.UserDetails
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.core.userdetails.UsernameNotFoundException
import org.springframework.stereotype.Service

@Service
class UserDetailServiceImpl : UserDetailsService {
    /**
     * 根据用户名获取用户信息
     */
    override fun loadUserByUsername(username: String): UserDetails {
        log.info("用户名为：{}", username)
        val jwtUser: JwtUser = JwtUser("1", "2", "3", setOf(), true, listOf())//调用远程服务
        //处理权限集合
        jwtUser.authorities = jwtUser.resources.map {
            SimpleGrantedAuthority("${it.method.uppercase()} ${it.url}")
        }.toSet()
        return jwtUser
    }

}